import { View } from "../../../../mvc/core/View";
import { ObjCreate } from "../../common/ObjCreate";
import { NormalBgItem } from "./NormalBgItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { Language } from "../../../../../extend/language/Language";
import { GuildUnionGuildItem } from "./GuildUnionGuildItem";
import { GuildUnionPosition } from "./rule/GuildUnionPosition";
import { GuildUnionAlloBar } from "./GuildUnionAlloBar";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GuildUnionRulePanel } from "./rule/GuildUnionRulePanel";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { SMyGuildUnion } from "../../../../../Message/Game/SMyGuildUnion";
import { Cache } from "../../../cache/Cache";
import { HighlightManager } from "../../../manager/HighlightManager";
import { FlowerBg } from "../../common/FlowerBg";
import { ScaleBitmap } from "../../../../../com/mui/display/ScaleBitmap";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { GBitmap } from "../../../../../com/mui/controls/GBitmap";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class GuildUnionPanel
    
    export  class GuildUnionPanel extends View
    {
        constructor()
        {
            super();
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStageHandler);
            return;
        }

        protected /* override */ createDisposedChildrenImpl(): void
        {
            this._bg1 = ObjCreate.createFlowerBg(5, 5, 660, 80, this);
            this._bg2 = ObjCreate.createBg(5, 88, 660, 290, this);
            this._unionIcon = new NormalBgItem();
            this._unionIcon.x = 60;
            this._unionIcon.y = 15;
            this.addChild(this._unionIcon);
            this._unionRuleText = ObjCreate.createGTextField("", 150, 15, 450, 80, this, GlobalStyle.setTextFormatLeading(GlobalStyle.textFormat1, 5));
            this._unionRuleText.htmlText = HTMLUtil.addColor(Language.getString(60851), GlobalStyle.color5);
            this._unionRuleText.addEventListener(flash.events.TextEvent.LINK, this.onRuleTextClickHandler);
            this._guildMain = new GuildUnionGuildItem(GuildUnionPosition.GuildUnionPositionOne);
            this._guildMain.x = 240;
            this._guildMain.y = 95;
            this.addChild(this._guildMain);
            this._guildLeft = new GuildUnionGuildItem(GuildUnionPosition.GuildUnionPositionTwo);
            this._guildLeft.x = 35;
            this._guildLeft.y = 95;
            this.addChild(this._guildLeft);
            this._guildRight = new GuildUnionGuildItem(GuildUnionPosition.GuildUnionPositionThree);
            this._guildRight.x = 445;
            this._guildRight.y = 95;
            this.addChild(this._guildRight);
            this._liyifenpeiBm = ObjCreate.createGBitmap(null, 20, 322, this);
            this._progressBar = new GuildUnionAlloBar();
            this._progressBar.x = 95;
            this._progressBar.y = 315;
            this._progressBar.setSize(520, 36);
            this.addChild(this._progressBar);
            ObjCreate.createGTextField("100%", 615, 323, 60, 25, this, new GTextFormat(FontUtil.stXingkaiName, 18, 16776960));
            this._inviteListBtn = ObjCreate.createGButton(Language.getString(60860), 570, 382, 80, 26, this);
            this._inviteListBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onInviteListBtnClick);
            LoaderHelp.addResCallBack(ResFileConst.GuildUnion, this.onLoadedHandler);
            return;
        }

        /* internal  */onRemoveFromStageHandler(arg1): void
        {
            if (this._rulePanel && this._rulePanel.parent) 
            {
                this._rulePanel.parent.removeChild(this._rulePanel);
            }
            return;
        }

        /* internal  */onRuleTextClickHandler(arg1): void
        {
            this.showOrHideRuleTextPanel();
            return;
        }

        public showOrHideRuleTextPanel(): void
        {
            if (!this._rulePanel) 
            {
                this._rulePanel = new GuildUnionRulePanel();
                this._rulePanel.x = 685;
                this._rulePanel.y = -23;
            }
            if (this._rulePanel.parent) 
            {
                this._rulePanel.parent.removeChild(this._rulePanel);
            }
            else 
            {
                this.addChild(this._rulePanel);
            }
            return;
        }

        /* internal  */onLoadedHandler(): void
        {
            if (!isDisposed) 
            {
                this._unionIcon.setBitmapData(ImagesConst.GuildUnionIcon);
                this._liyifenpeiBm.bitmapData = GlobalClass.getBitmapData(ImagesConst.GuildUnionText1);
                this._guildMain.updateRes();
                this._guildLeft.updateRes();
                this._guildRight.updateRes();
            }
            return;
        }

        /* internal  */onInviteListBtnClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildUnionShowInviteList, GuildUnionPosition.GuildUnionPositionOne));
            return;
        }

        public updateGuildUnionInfo(arg1: SMyGuildUnion): void
        {
            this._guildMain.updateInfo(0, arg1.firstAllocation, arg1.firstGuildInfo);
            this._guildLeft.updateInfo(arg1.secondStatus, arg1.secondAllocation, arg1.secondGuildInfo);
            this._guildRight.updateInfo(arg1.thirdStatus, arg1.thirdAllocation, arg1.thirdGuildInfo);
            var loc1=arg1.secondGuildInfo ? arg1.secondGuildInfo.guildName : "";
            var loc2=arg1.firstGuildInfo ? arg1.firstGuildInfo.guildName : "";
            var loc3=arg1.thirdGuildInfo ? arg1.thirdGuildInfo.guildName : "";
            this._progressBar.setValues(arg1.secondAllocation, arg1.firstAllocation, arg1.thirdAllocation, loc1, loc2, loc3);
            this.updateGuildUnionApplyBtnStatus();
            return;
        }

        public updateGuildUnionApplyBtnStatus(): void
        {
            if (!Cache.instance.guildUnion.hasUnion && Cache.instance.guildUnion.hasApply && Cache.instance.guild.isGuildLeader && Cache.instance.guildUnion.isInActive) 
            {
                HighlightManager.instance.glowEffectButton(this._inviteListBtn, true);
            }
            else 
            {
                HighlightManager.instance.glowEffectButton(this._inviteListBtn, false);
            }
            return;
        }

        /* internal */ /* var */_bg1: FlowerBg;

        /* internal */ /* var */_bg2: ScaleBitmap;

        /* internal */ /* var */_unionIcon: NormalBgItem;

        /* internal */ /* var */_unionRuleText: GTextFiled;

        /* internal */ /* var */_rulePanel: GuildUnionRulePanel;

        /* internal */ /* var */_guildMain: GuildUnionGuildItem;

        /* internal */ /* var */_guildLeft: GuildUnionGuildItem;

        /* internal */ /* var */_guildRight: GuildUnionGuildItem;

        /* internal */ /* var */_liyifenpeiBm: GBitmap;

        /* internal */ /* var */_progressBar: GuildUnionAlloBar;

        /* internal */ /* var */_inviteListBtn: GButton;
    }
